using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using yq.IBase;
using yq.Dictionary;
using yq.Basis;
using yq.Model.Logic;
using System.Collections;
using Db;
using System.Data.Common;

namespace yq.Model.Base
{
    ///<summary>
    /// Purview_Page - 权限详细 - 对象基础类
    /// </summary>
    ///<typeparam name="T"></typeparam>
    public abstract class IPurviewPage<T> : ModelBase<PurviewPage> where T : PurviewPage, new()
    {
        /// <summary>
        /// 写入主键值
        /// </summary>
        /// <param name="Id">主键</param>
        protected internal override void SetKeyValue(dynamic Id)
        {
            this.PwId = Id;
        }

        /// <summary>
        /// 获取主键值
        /// </summary>
        /// <returns></returns>
        protected internal override dynamic GetKeyValue()
        {
            return PwId;
        }

        /// <summary>
        /// 为本对象赋值
        /// </summary>
        /// <param name="dy"></param>
        public override void SetValue(dynamic dy)
        {
            this.PwId = dy.PwId;
            this.Name = dy.Name;
            this.Path = dy.Path;
            this.IsOpen = dy.IsOpen;
            this.Type = dy.Type;
            this.PurviewEnum = dy.PurviewEnum;
            this.Detailed = dy.Detailed;
            this.Version = dy.Version;
        }

        #region 定义属性


        /// <summary>
        /// 权限ID
        /// </summary>
        private String _PwId = "";

        /// <summary>
        /// 权限ID
        /// </summary>
        public String PwId
        {
            get
            {
                return (this._PwId);
            }

            set
            {
                _PwId = value;
            }
        }


        /// <summary>
        /// 权限名称
        /// </summary>
        private String _Name = "";

        /// <summary>
        /// 权限名称
        /// </summary>
        public String Name
        {
            get
            {
                return (this._Name);
            }

            set
            {
                _Name = value;
            }
        }


        /// <summary>
        /// 权限路径
        /// </summary>
        private String _Path = "";

        /// <summary>
        /// 权限路径
        /// </summary>
        public String Path
        {
            get
            {
                return (this._Path);
            }

            set
            {
                _Path = value;
            }
        }


        /// <summary>
        /// 是否开启
        /// </summary>
        private int _IsOpen = -1;

        /// <summary>
        /// 是否开启
        /// </summary>
        public yq.Enums.BooleanType IsOpen
        {
            get
            {
                return (yq.Enums.BooleanType)_IsOpen;
            }

            set
            {
                _IsOpen = value.GetHashCode();
            }
        }


        /// <summary>
        /// 权限类别
        /// </summary>
        private int _Type = -1;

        /// <summary>
        /// 权限类别
        /// </summary>
        public yq.Enums.PurviewPage.Type Type
        {
            get
            {
                return (yq.Enums.PurviewPage.Type)this._Type;
            }

            set
            {
                _Type = value.GetHashCode();
            }
        }


        /// <summary>
        /// 权限组
        /// </summary>
        private int _PurviewEnum = -1;

        /// <summary>
        /// 权限组
        /// </summary>
        public yq.Enums.PurviewPage.PurviewEnum PurviewEnum
        {
            get
            {
                return (yq.Enums.PurviewPage.PurviewEnum)this._PurviewEnum;
            }

            set
            {
                _PurviewEnum = value.GetHashCode();
            }
        }


        /// <summary>
        /// 说明
        /// </summary>
        private String _Detailed = "";

        /// <summary>
        /// 说明
        /// </summary>
        public String Detailed
        {
            get
            {
                return (this._Detailed);
            }

            set
            {
                _Detailed = value;
            }
        }



        #endregion 定义属性

        protected internal override void SetValue(PurviewPage info, DataRow row)
        {
            if (row == null)
            {
                info.IsLoad = false;
            }
            else
            {
                info.IsLoad = true;

                if (row["PwId"] != DBNull.Value)
                {
                    info.PwId = row["PwId"].ToString();
                }


                if (row["Name"] != DBNull.Value)
                {
                    info.Name = row["Name"].ToString();
                }


                if (row["Path"] != DBNull.Value)
                {
                    info.Path = row["Path"].ToString();
                }


                if (row["IsOpen"] != DBNull.Value)
                {
                    info.IsOpen = (yq.Enums.BooleanType)(row["IsOpen"]);
                }


                if (row["Type"] != DBNull.Value)
                {
                    info.Type = (yq.Enums.PurviewPage.Type)(row["Type"]);
                }


                if (row["PurviewEnum"] != DBNull.Value)
                {
                    info.PurviewEnum = (yq.Enums.PurviewPage.PurviewEnum)(row["PurviewEnum"]);
                }


                if (row["Detailed"] != DBNull.Value)
                {
                    info.Detailed = row["Detailed"].ToString();
                }


                if (row["Version"] != DBNull.Value)
                {
                    info.Version = row["Version"].ToString();
                }

            }

        }

        protected internal override void GetDbParameters(DbCommand comm, PurviewPage info, DbHelper cn)
        {

            cn.AddInParameter(comm, "@PwId", DbType.String, ParameterTool.GetObj(info._PwId));


            cn.AddInParameter(comm, "@Name", DbType.String, ParameterTool.GetObj(info._Name));


            cn.AddInParameter(comm, "@Path", DbType.String, ParameterTool.GetObj(info._Path));


            cn.AddInParameter(comm, "@IsOpen", DbType.Int32, ParameterTool.GetObj(info._IsOpen));


            cn.AddInParameter(comm, "@Type", DbType.Int32, ParameterTool.GetObj(info._Type));


            cn.AddInParameter(comm, "@PurviewEnum", DbType.Int32, ParameterTool.GetObj(info._PurviewEnum));


            cn.AddInParameter(comm, "@Detailed", DbType.String, ParameterTool.GetObj(info._Detailed));


            cn.AddInParameter(comm, "@Version", DbType.String, Guid.NewGuid().ToString());


            cn.AddInParameter(comm, "@_versionOdl", DbType.String, info._Version);

        }

    }
}